<?php

namespace App\Http\Controllers;

use App\Models\FundPlan;
use App\Models\ProjectComment;
use App\Models\RoleUser;
use App\Models\Throughtrain;
use App\Models\Role;
use App\Models\ThroughtrainComment;
use Illuminate\Http\Request;
use \DB;
use App\Http\Requests;
use App\Http\Controllers\CommonController;
use Illuminate\Http\Response;
use App\Http\Requests\ZtcRequest;
use Illuminate\View\View;
use App\Models\User;
use App\User as aUser;

class PlanController extends CommonController
{
    public function getIndex()
    {
        $lists = FundPlan::orderBy('id', 'desc')->paginate(10);

        return view('plan.index')->with('lists', $lists)->with('actions', $this->actions);
    }


    public function getCreate()
    {

        return view('plan.create');
    }


    public function postCreate(Request $request)
    {
        $data = $request->input();

        FundPlan::create(['name'=>$data['name']]);

        return AjaxCallbackMessage('创建成功', true, url('plan/index'));
    }



    public function getEdit(Request $request)
    {
        $data = $request->input();
        $list = FundPlan::where('id', $data['id'])->first();

        return view('plan.edit')->with('list', $list);
    }


    public function postEdit(Request $request)
    {
        $data = $request->input();
        FundPlan::where('id',$data['id'])->update(['name'=>$data['name'], 'status'=>$data['status']]);

        return AjaxCallbackMessage('编辑成功', true, url('plan/index'));
    }


    public function postDelete(Request $request)
    {
        $data = $request->input();
        FundPlan::where('id', $data['pid'])->delete();

        return AjaxCallbackMessage('删除成功', true, url('plan/index'));
    }
}
